﻿using Silverlight.Training.Client.Common.ServiceReference.EventArgs;
using Silverlight.Training.Client.Common.ServiceReference.Contracts;

namespace SilverLight.Training.Models
{
    public class EmployeeDetailsModel : ModelBase
    {
        public event System.EventHandler<CollectionFeedbackCompletedEventArgs<Employee>> GetEmployeeCollectionCompleted;
        public event System.EventHandler<SingleFeedbackCompletedEventArgs<Employee>> GetSingleEmployeeCompleted;

        public EmployeeDetailsModel() : base()
        {
            client.GetEmployeeCollectionCompleted += client_GetEmployeeCollectionCompleted;
            client.GetSingleEmployeeCompleted += client_GetSingleEmployeeCompleted;
        }

        public void GetEmployeeCollectionAsync()
        {
            client.GetEmployeeCollectionAsync();
        }

        public void GetSingleEmployeeAsync(int employeeID)
        {
            client.GetSingleEmployeeAsync(employeeID);
        }

        void client_GetSingleEmployeeCompleted(object sender, SingleFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetSingleEmployeeCompleted != null)
            {
                GetSingleEmployeeCompleted(sender, e);
            }
        }

        void client_GetEmployeeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetEmployeeCollectionCompleted != null)
            {
                GetEmployeeCollectionCompleted(sender, e);
            }
        }
    }
}
